﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class sleep : MonoBehaviour
{
    public InputField Instruction;
    public bool canSleep;
    public GameObject Dog;
    public GameObject endManager;
    public Image Black;
    public Animator DogAnim;
    public bool ending;
    public float numb=0;
    
    private void Start()
    {
        DogAnim = Dog.GetComponent<Animator>();
        
    }
    // Start is called before the first frame update
    private void OnTriggerEnter2D(Collider2D collision)
    {
        canSleep = true;
    }
    private void OnTriggerExit2D(Collider2D collision)
    {
        canSleep = false;
    }
    private void Update()
    {
        if (canSleep)
        {
            if (Instruction.text == "sleep")
            {
                DogAnim.SetBool("sleeping",true);
                ending = true;
            }
        }
        if(ending==true)
        {
            numb+=0.001f;
            Black.GetComponent<Image>().color = new Color(0, 0, 0, numb);
            endManager.SetActive(true);
        }

    }
}
